package com.qsw.fileoperatelib.test.bean;

import com.qsw.fileoperatelib.excel.bean.impl.IExportExcel;

import java.util.LinkedList;
import java.util.List;

public class FolTestExcelBean implements IExportExcel {

    private int testInt1;
    private int testInt2;
    private String testString1;
    private String testString2;

    public FolTestExcelBean() {
    }

    public FolTestExcelBean(int testInt1, int testInt2, String testString1, String testString2) {
        this.testInt1 = testInt1;
        this.testInt2 = testInt2;
        this.testString1 = testString1;
        this.testString2 = testString2;
    }

    public int getTestInt1() {
        return testInt1;
    }

    public void setTestInt1(int testInt1) {
        this.testInt1 = testInt1;
    }

    public int getTestInt2() {
        return testInt2;
    }

    public void setTestInt2(int testInt2) {
        this.testInt2 = testInt2;
    }

    public String getTestString1() {
        return testString1;
    }

    public void setTestString1(String testString1) {
        this.testString1 = testString1;
    }

    public String getTestString2() {
        return testString2;
    }

    public void setTestString2(String testString2) {
        this.testString2 = testString2;
    }

    @Override
    public List<String> getColumnName() {
        List<String> list = new LinkedList<>();
        list.add("testInt1");
        list.add("testInt2");
        list.add("testString1");
        list.add("testString2");
        return list;
    }

    @Override
    public List<String> toList() {
        List<String> list = new LinkedList<>();
        list.add(String.valueOf(testInt1));
        list.add(String.valueOf(testInt2));
        list.add(testString1);
        list.add(testString2);
        return list;
    }

    @Override
    public IExportExcel fromList(String[] data) {
        for (int i = 0; i < data.length; i++) {
            if (i == 0) {
                try {
                    testInt1 = Integer.parseInt(data[i]);
                } catch (NumberFormatException e) {
                    continue;
                }
            } else if (i == 1) {
                try {
                    testInt2 = Integer.parseInt(data[i]);
                } catch (NumberFormatException e) {
                    continue;
                }
            } else if (i == 2) {
                testString1 = data[i];
            } else if (i == 3) {
                testString2 = data[i];
            }
        }
        return this;
    }

    @Override
    public String toString() {
        return "FolTestExcelBean{" +
                "testInt1=" + testInt1 +
                ", testInt2=" + testInt2 +
                ", testString1='" + testString1 + '\'' +
                ", testString2='" + testString2 + '\'' +
                '}';
    }
}
